package com.seres.user.controller.api.dict;

import com.baomidou.mybatisplus.core.metadata.IPage;

import com.seres.annotation.AuthToken;
import com.seres.response.ApiResponse;
import com.seres.user.service.dict.IDictService;
import com.seres.user.vo.dict.DictReq;
import com.seres.user.vo.dict.DictRes;
import com.seres.util.BaseController;
import com.seres.util.PageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Tan-Bowen
 * @version 1.0
 * @description TODO
 * @date 2021/7/27 14:52
 */

@Api(value = "数据字典", tags = "字典信息")
@Slf4j
@RestController
@RequestMapping("/api/dict")
public class DictController extends BaseController {
    @Resource
    private IDictService dictService;

    @AuthToken(checkPower = false)
    @PostMapping("/page")
    @ApiOperation(value = "字典列表查询")
    public ApiResponse<IPage<DictRes.Page>> deptPage(PageUtil.Pages page, DictReq.Query select) {
        return ApiResponse.success(dictService.pages(select, getPage(page)));
    }


    @AuthToken(checkPower = false)
    @PostMapping("/create")
    @ApiOperation(value = "字典新增")
    public ApiResponse<Void> create(@Validated DictReq.Create request) {
        dictService.create(request);
        return ApiResponse.success();
    }

    @AuthToken(checkPower = false)
    @PostMapping("/update")
    @ApiOperation(value = "字典编辑")
    public ApiResponse<Void> update(@Validated DictReq.Update update) {
        dictService.update(update);
        return ApiResponse.success();
    }

    @AuthToken(checkPower = false)
    @GetMapping("/getDictList")
    @ApiOperation(value = "获取字典信息")
    public ApiResponse<List<DictRes.Page>> getDictList(DictReq.Query query) {
        return ApiResponse.success(dictService.dictList(query));
    }

    @AuthToken(checkPower = false)
    @PostMapping("/delDict")
    @ApiOperation(value = "删除字典信息")
    public ApiResponse<Void> delDict(@RequestParam("id")Long id) {
        dictService.delDict(id);
        return ApiResponse.success();
    }


}